package tony.com.xframe.widge;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import tony.com.xframe.R;
import tony.com.xframe.utils.ScreenUtils;

/**
 * Created by Tony on 2016-01-03.
 */
public class CurrentToast extends Toast {
    public static CurrentToast currentToast;
    public Toast toast;
    private static Context context;

    public static CurrentToast getInstance(Context context) {
        if (currentToast == null) {
            currentToast = new CurrentToast(context);
        }
        return currentToast;
    }

    private CurrentToast(Context context) {
        super(context);
        this.context = context;
    }

    public void toastShow(String message) {
        View view = LayoutInflater.from(context).inflate(R.layout.current_toast, null);
        TextView textView = (TextView) view.findViewById(R.id.tv_message);
        //因为父类布局match_parent无效，所以自己写一个布局
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ScreenUtils.getScreenWidth(context), ViewGroup.LayoutParams.MATCH_PARENT);
        textView.setLayoutParams(params);
        textView.setText(message);
        toast = new Toast(context);
        toast.setView(view);


        toast.setGravity(Gravity.TOP, 0, 0);


        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
    }

}
